﻿using EFCoreDemo.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace EFCoreDemo.Repository
{
    public interface IRepository<T> : IQueryable<T> where T : class, IEntity
    {
        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        T Add(T entity);

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        T Update(T entity);

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="entity"></param>
        void Delete(T entity);

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        void Delete(long id);

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="entitys"></param>
        int DeleteRange(IEnumerable<T> delDatas);

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="entitys"></param>
        int DeleteRange(Expression<Func<T, bool>> predicate);

        /// <summary>
        /// 获取单条数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        T Get(long id);

        /// <summary>
        /// 获取查询表达式
        /// </summary>
        /// <returns></returns>
        IQueryable<T> Queryable { get; }

        int ExecuteSql(FormattableString sql);
        int ExecuteSql(string sql);
    }
}
